package com.xd.cloud.dao.device;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.xd.cloud.dao.BaseDao;
import com.xd.cloud.entity.core.Team;

/**   
 * 功能描述：车队信息Dao
 * @author: wangshanshan   
 * @date: 2017年12月14日 下午16:10:12 
 */
@Repository
public class TeamDao extends BaseDao<Team> {

	public Team getTeamById(int id) {
		String hql = "from Team where id = ?";
		return get(hql, new Object[]{id});
	}
	
	public List<Team> getTeamByCompanyId(int company_id) {
		String hql = "from Team where company_id =? and status=1";
		return find(hql, new Object[]{company_id});
	}

	public List<Object[]> getVehicleByCompanyId(int company_id) {
		String sql = "select v.devicecode,v.companyid,v.vehid from tb_vehicle v where v.devicecode is not null and v.companyid = ? and v.id not in(select vehicle_id from tb_vehicle_team) order by v.id ";
		return findSql(sql, new Object[]{company_id});
	}
	
	public List<Object[]> getTeamVehicleByCompanyId(int company_id) {
		String sql = "select t.id,t.company_id,t.name,v.devicecode,t.id team_id,v.vehid " + 
				"from sys_team t,tb_vehicle_team vt,tb_vehicle v " + 
				"where t.id = vt.team_id and vt.vehicle_id = v.id and v.devicecode is not null and t.company_id = ? order by t.id ";
		return findSql(sql, new Object[]{company_id});
	}
}
